package com.shangjinrong.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shangjinrong.domain.Borrower;
import com.shangjinrong.domain.vo.BorrowerApprovalVO;
import com.shangjinrong.result.R;
import com.shangjinrong.service.BorrowerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("admin/borrower")
@Slf4j
public class AdminBorrowerController {

    @Autowired
    BorrowerService borrowerService;

    @GetMapping("paging/{current}/{size}")
    public R paging(@PathVariable long current, @PathVariable long size, String keyword) {
        if (null == keyword) keyword = "";
        Page<Borrower> page = new Page<>(current, size);
        borrowerService.paging(page, keyword);
        return R.ok().data("paging", page).message("ok");
    }

    @GetMapping("detail/{id}")
    public R detail(@PathVariable long id){
        return R.ok().data("borrower",borrowerService.getBorrowerDetailVoById(id));
    }

    @PostMapping("approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }

}
